package com.atguigu.serviceoss.controller;

import com.atguigu.serviceoss.service.OSSService;
import com.atguigu.srb.result.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * ClassName: OSSController
 * Package: com.atguigu.serviceoss.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/4/20 8:42
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/oss")
@Api(tags = "阿里云OSS服务")
public class OSSController {
    @Autowired
    private OSSService ossService;

    @ApiOperation("文件上传")
    @PostMapping
    public ResponseVo fileUpload(MultipartFile file,@RequestParam("dir") String dir){
        String fileUrl = ossService.fileUpload(file,dir);
        return ResponseVo.ok().addData("path",fileUrl);
    }

    @ApiOperation("文件删除")
    @DeleteMapping
    public ResponseVo delete(@RequestParam("url") String  url){
        ossService.delete(url);
        return  ResponseVo.ok().message("文件删除成功");
    }

}
